<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.courseserial.dao.ICourseSerialDAO" %>
                                         

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String style1 = "width: 40%;text-align:center;font-size: 12px;";
String style2 = "text-align:left;width: 100px";

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ICourseSerialDAO dao = (ICourseSerialDAO) context.getBean("CourseSerialDAO");
List list = dao.queryTicketStatusList();


String userid = request.getSession().getAttribute("userid").toString();


%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	    <link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>">

		<title>一级菜系</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="">
		<meta http-equiv="description" content="一级菜系">
		
		<style type="text/css"> 
			@import "js/tableview/TableView.css";
    	</style>
	</head>
	
	<body onload="onClickQuery()">
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/tableview/SortView.js"></script>
		<script type="text/javascript" src="js/tableview/PagerView.js"></script>
		<script type="text/javascript" src="js/tableview/TableView.js"></script>
		<script type="text/javascript" src="js/tableview/SelectorView.js"></script>
		<script type="text/javascript" src="js/tableview/PaperView.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		<table width="100%" height="50px" border="0" cellpadding="0" cellspacing="0">
	  	 
	  	<tr>
		  	<td class="title0">一级菜系</td>		  	
	  	</tr>
	  	
	  	</table>
		<table width="100%" height="100px" border="0" cellpadding="0" cellspacing="0">	
		 	<tr>
		  		<td colspan="2" style="<%=style1%>">
		  		
  		  			<lable style="<%=style1%>">一级菜系名称&nbsp;</lable>
		
			  		<input  type="text" id="input_name" name="input_name"  style="<%=style2%>">
		
		  		
            		<input type="button" id="btn_query" name="btn_query" value="查找" onclick="onClickQuery()">
            		<input type="button" id="btn_add" name="btn_add" value="添加" onclick="addCourseSerial()">
	  			</td>
		  	
  			</tr>  
	  		<tr>
		  		<td colspan="2">
				  	<div id="table_div" style= "width: 100%"></div>
					<div id="pager"></div>
				</td>
			</tr>
	  	</table>

		<script type="text/javascript">
		
		var numPerPage = 10; //每页行数
		var paramValue = ""; //形如  "{STATUS:'1', CREATE_MANAGER:'1'}"
		var methodCount = "queryCourseSerialCount";
		var methodPage = "queryCourseSerialPage";
		
		var table = new TableView('table_div');
		table.header = {
			NAME			: '一级菜系名称',
			UPT				: '修改',
			DEL				: '删除'	

		};
		table.customDefine = {
				NAME			: 'width = "250px"',
				UPT				: '',
				DEL				: ''	
		};
		
		table.dataKey = 'SERIAL_ID';
		table.count = false;
		table.title = false;
		table.display.filter = false;
		table.display.pager = false;
		table.pager.size = numPerPage;

		var pager = new PagerView('pager');
		pager.onclick = onPagerClick;
		pager.itemCount = 0;
		pager.size = numPerPage;
		
		table.render();
		pager.render();

		function queryCourseSerial(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * numPerPage + 1;
  	  		var end = pageNO * numPerPage;
  	  		var mc = returnCount==true ? methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "CourseSerialBMO.queryCourseSerial",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				data: date,
				datatype:"json",
				success: query_success,
				error: show_error
  	  		});
  			return true;
  			
  		}
  		function onPagerClick(pageNO) {
  			queryCourseSerial(pageNO, "FLASE");
  		}

  		//刷新当前页
  		function refreshCurrentPage() {
  			queryTicket(pager.index, "FLASE");
  		}
  		
  		function query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		pager.itemCount = jdata.COUNT;
  	  	  		pager.size = numPerPage;  	  	  		
  	  	  		pager.render();
  	  		} 
		   var array = eval(jdata.LIST);
		   		for(var i = 0; i < array.length; ++i) {
		   		var url = "<input type=\"button\" value=\"修改\" onclick=\"onUpt('";
		   		url += array[i].SERIAL_ID;
		   		url += "')\" />";
		   		array[i].UPT = url;
		   		
		   		url = "<input type=\"button\" value=\"删除\" onclick=\"onDel('";
		   		url += array[i].SERIAL_ID;
		   		url += "')\" />";
		   		array[i].DEL = url;
		   }
		   table.clear();
		   table.addRange(array);
		}
  		function show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		}
 		
 		function addCourseSerial() {
  			var url = "<%=path%>";
  			url += "/courseserial/addCourseSerial.do";
  			var param = "status:no;scroll:no;dialogWidth:400px;dialogHeight:300px";
			window.showModalDialog(url, window, param); 
 		}
 		
  		function onClickQuery() {
  	  		
  			var tmp = document.getElementById("input_name").value;
			
			paramValue = "";
  			paramValue += "{NAME:";
  			paramValue += "'" + tmp + "'";  
			paramValue += ", SERIAL_LEVEL:'1'}";
  		
  	  		pager.index = 1;
  	  		queryCourseSerial(1, true);
  		}
  		function onUpt(serial_id) {
  			var url = "<%=path%>";
  			url += "/courseserial/editCourseSerial.do?serial_id=" + serial_id;
  			var param = "status:no;scroll:no;dialogWidth:400px;dialogHeight:300px";
			window.showModalDialog(url, window, param); 			
  		}  	
  			
		function onDel(serial_id) {
			if (confirm('其下级菜系也会一并删除,您确定要删除吗?')) {
				var param = "{SERIAL_ID:";
	  			param += "'"+serial_id+"'";
	  			param += "}";

	  			$.ajax({
					type: "POST",
					url: "courseserial/delCourseSerial.ajax",
					data: {PARAM:param, OPERATE_TYPE:"DEL", RETURNTYPE:'MESSAGE'},
					datatype:"json",
					success: okSuccess,
					error: show_error
	  	  		});
  	  		}
  		} 
 
		function showMsg(data) {
  	  		alert(data);
 		}
 		function okSuccess(data) {
  	  		alert(data);
  	  		onClickQuery();  	  		
 		}
	</script>
	
	</body>
</html>
